package com.zy.servlet.yhgl;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.sun.jmx.remote.util.Service;
import com.zhang.sys.SysUser;
import com.zy.service.YhglService;

public class ModifyUser extends HttpServlet {

	private static final long serialVersionUID = 1L;
	private static final Logger log = LoggerFactory.getLogger(AddUser.class);
	
	@SuppressWarnings("unchecked")
	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
			this.doPost(request, response);
	}

	
	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {

		response.setCharacterEncoding("UTF-8");
		response.setContentType("appliaction/x-json;charset=utf-8");
		PrintWriter out = response.getWriter();
		String id=request.getParameter("userId1");
		String username=request.getParameter("username1");
		String password=request.getParameter("password1");
		String confirPassword=request.getParameter("confirPassword1");
		String sex=request.getParameter("sex1");
		String role=request.getParameter("role1");
		String flag=request.getParameter("flag1");
		String csid=request.getParameter("csid1");
		SysUser user=new SysUser();
		try {
			if (id != null && !id.equals("") && username != null
					&& !username.equals("") && password != null
					&& !password.equals("") && sex != null && !sex.equals("")
					&& flag != null && !flag.equals("") && role != null
					&& !role.equals("") && csid != null && !csid.equals("")
					&& confirPassword.equals(password)) {
				YhglService Service = new YhglService();
				user.setUserId(id);
				user.setUserName(username);
				user.setPasswd(password);
				user.setRoleId(role);
				user.setSex(sex);
				user.setUserFlag(flag);
				user.setGroupId(csid);
				Service.ModifyUser(user);
				out.println("{success:true,data:{rs:1}}");

			} else {
				out.println("{success:true,data:{rs:2}}");
			}

		} catch (RuntimeException e) {
			out.println("{success:false}");
			e.printStackTrace();
		}
	
		out.println();
		out.flush();
		out.close();
	}

}
